#!/usr/bin/env python
# -*- coding:utf-8 -*-


class MemberRewardHistoryObj:
    UPGRADE_TYPE_CHARGE = "1000"
    UPGRADE_TYPE_RIGHT = "1000"
    UPGRADE_TYPE_POINTS = "3000"
    UPGRADE_TYPE_CUTREG = "4000"

    UPGRADE_TYPE = {
        "1000": "充值",
        "2000": "购买权益",
        "3000": "积分",
        "4000": "人工注册",
    }

    col_keys = ["id", "member_id", "create_date", "way", "points", "memo"]
    col_def_val = [float(0), "", None, float(0), float(0), ""]

    id: float(0)
    member_id: ""
    create_date: None
    way: float(0)
    points: float(0)
    memo: ""

    def __init__(self):
        return

    @staticmethod
    def split_params(params):
        import math
        g_param = []
        if params['member_id'] is not None and len(params['member_id']) > 0:
            g_param.append('`member_id`=' + "\'" + str(params['member_id']) + "\'")
        if params['create_date'] is not None and len(params['create_date']) > 0:
            g_param.append('`create_date`=' + "\'" + params['create_date'] + "\'")
        if params['way'] is not None and len(params['way']) > 0:
            g_param.append('`way`=' + "\'" + str(params['way']) + "\'")
        if params['points'] is not None and math.fabs(int(params['points'])) > 0:
            g_param.append('`points`=' + "\'" + params['points'] + "\'")
        if params['memo'] is not None and len(params['memo']) > 0:
            g_param.append('`memo`=' + "\'" + params['memo'] + "\'")
        return ', '.join(str(i) for i in g_param)

    @staticmethod
    def concat_datas(g_param):
        from datetime import datetime
        current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        arry = [g_param["member_id"], current_time, g_param["way"], g_param["points"], g_param["memo"]]
        _res = []
        for _val in arry:
            if isinstance(_val, str):
                _res.append(f"\'{_val}\'")
            else:
                if _val is None:
                    _res.append("null")
                else:
                    _res.append(_val)
        return ', '.join(str(i) for i in _res)

    @staticmethod
    def load_db_2_dict(data):
        g_param = {}
        g_param["id"] = data[0]
        g_param["member_id"] = data[1]
        g_param["create_date"] = str(data[2])
        g_param["way"] = data[3]
        g_param["points"] = data[4]
        g_param["memo"] = data[5]
        g_param["waystr"] = MemberRewardHistoryObj.UPGRADE_TYPE[data[3]]
        return g_param

    # 标记为true时候，从DBA中读取数据，附带ID主键，标记为false时候忽略自增型字段ID
    @staticmethod
    def to_string(with_flg):
        g_param = []
        if with_flg:
            g_param.append("`mem_member_reward_history`.`id`")
            g_param.append("`mem_member_reward_history`.`member_id`")
            g_param.append("`mem_member_reward_history`.`create_date`")
            g_param.append("`mem_member_reward_history`.`way`")
            g_param.append("`mem_member_reward_history`.`points`")
            g_param.append("`mem_member_reward_history`.`memo`")
        else:
            g_param.append("`member_id`")
            g_param.append("`create_date`")
            g_param.append("`way`")
            g_param.append("`points`")
            g_param.append("`memo`")
        return ', '.join(str(i) for i in g_param)
